/*
* Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Main.
*/

#include <QtGui/qapplication.h>
#include <QtCore/qobject.h>
#include <QtDeclarative/qdeclarativecontext.h>

#include "main.h"
#include "qmlapplicationviewer.h"
#include "src/location/locationgesturearea.h"
#include "src/location/locationmanager.h"
#include "src/connection/connectionengine.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    qmlRegisterType<LocationGestureArea>("MyGestureArea", 1, 0, "LocationGestureArea");

    QmlApplicationViewer viewer;

    // Create LocationManager and ConnectionEngine instances and
    // expose their properties to be referenced from QML code.
    QDeclarativeContext *m_context = viewer.rootContext();
    LocationManager *locModel = new LocationManager(&viewer);
    m_context->setContextProperty("locationManager", locModel);

    ConnectionEngine *connModel = new ConnectionEngine(&viewer);
    m_context->setContextProperty("connectionEngine", connModel);

    // Create connection to send location to other device.
    QObject::connect(locModel, SIGNAL(sendLocation(const QByteArray&)), connModel, SLOT(shareData(const QByteArray&)));
    // Create connection to receive location from other device.
    QObject::connect(connModel, SIGNAL(messageReceived(const QByteArray&)), locModel, SLOT(receiveLocation(const QByteArray&)));
    // Create connection to receive notification when devices have connected.
    QObject::connect(connModel, SIGNAL(newConnection(QString)), locModel, SIGNAL(deviceConnected(QString)));
    // Create connection to receive notification when devices have disconnected.
    QObject::connect(connModel, SIGNAL(connectionClosed(QString)), locModel, SIGNAL(deviceDisconnected(QString)));

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qml/LocationApp/main.qml"));
    viewer.showExpanded();
    return app.exec();
}
